#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

// 567. 字符串的排列
// https://leetcode.cn/problems/permutation-in-string/description/

class Solution
{
public:
    bool checkInclusion(string s1, string s2)
    {
        int diff = 0;
        int left = 0;
        int windowsLen = s1.size();

        vector<int>recordChar(26);
        for(auto it : s1){
            recordChar[it - 'a']++;
        }

        vector<int> curChar(26);
        for (int i = 0; i < s2.size(); i++)
        {
            int curIndex = s2[i] - 'a';
            curChar[curIndex]++;

            if(curChar[curIndex] > recordChar[curIndex]){
                diff++;
            }

            if (i - left + 1 < windowsLen)
            {
                continue;
            }
            
            if(diff == 0){
                return true;
            }

            curChar[s2[left] - 'a']--;
            if (curChar[s2[left] - 'a'] >= recordChar[s2[left] - 'a'])
            {
                diff--;
            }
            left++;
        }
        return false;
    }
};

int main()
{
    return 0;
}